﻿#include<iostream>
#include<map>
#include<set>
#include<string>
#include<vector>
using namespace std;

void TestSet()
{
	/*set<string> s({"hello"});
	set<string> s1 = { { "hello" }, {"hj"} };
	s1.insert("sort");

	for (auto e : s1)
	{
		cout << e << endl;
	}

	multiset<string> ms;
	ms.insert("hello");
	ms.insert("hello");
	ms.insert("hello");
	ms.insert("hello");
	ms.erase("hello");
	for (auto e : ms)
	{
		cout << e << endl;
	}*/

	//// 去重+升序排序
	//set<int> s;
	//// 去重+降序排序（给⼀个⼤于的仿函数）
	////set<int, greater<int>> s;
	//s.insert(5);
	//s.insert(2);
	//s.insert(7);
	//s.insert(5);
	////set<int>::iterator it = s.begin();
	//auto it = s.begin();
	//while (it != s.end())
	//{
	//		// error C3892: “it”: 不能给常量赋值
	//		// *it = 1;
	//		cout << *it << " ";
	//	++it;
	//}
	//cout << endl;
	//// 插⼊⼀段initializer_list列表值，已经存在的值插⼊失败
	//s.insert({ 2,8,3,9 });
	//for (auto e : s)
	//{
	//	cout << e << " ";
	//}
	//cout << endl;
	//set<string> strset = { "sort", "insert", "add" };
	//// 遍历string⽐较ascll码⼤⼩顺序遍历的
	//for (auto& e : strset)
	//{
	//	cout << e << " ";
	//}
	//cout << endl;


	//set<int> s = { 4,2,7,2,8,5,9 };
	//for (auto e : s)
	//{
	//	cout << e << " ";
	//}
	//cout << endl;
	//// 删除最⼩值
	//s.erase(s.begin());
	//for (auto e : s)
	//{
	//	cout << e << " ";
	//}

	//	cout << endl;
	//// 直接删除x
	//int x;
	//cin >> x;
	//int num = s.erase(x);
	//if (num == 0)
	//{
	//	cout << x << "不存在！" << endl;
	//}
	//for (auto e : s)
	//{
	//	cout << e << " ";
	//}
	//cout << endl;
	//// 直接查找在利⽤迭代器删除x
	//cin >> x;
	//auto pos = s.find(x);
	//if (pos != s.end())
	//{
	//	s.erase(pos);
	//}
	//else
	//{
	//	cout << x << "不存在！" << endl;
	//}
	//for (auto e : s)
	//{
	//	cout << e << " ";
	//}
	//cout << endl;
	//// 算法库的查找 O(N)
	//auto pos1 = find(s.begin(), s.end(), x);
	//// set⾃⾝实现的查找 O(logN)
	//auto pos2 = s.find(x);
	//// 利⽤count间接实现快速查找
	//cin >> x;
	//if (s.count(x))
	//{
	//	cout << x << "在！" << endl;
	//}
	//else

	//{
	//cout << x << "不存在！" << endl;
	//}

	std::set<int> myset;
	for (int i = 1; i < 10; i++)
		myset.insert(i * 10); // 10 20 30 40 50 60 70 80 90

	auto itlow = myset.lower_bound(30);
	auto itup = myset.upper_bound(60);
	for (auto e : myset)
	{
		cout << e << " ";
	}
	cout << endl;
	myset.erase(itlow, itup);

	for (auto e : myset)
	{
		cout << e << " " ;
	}
	cout << endl;
}


void TestMap()
{
	/*map<string, string> mp;
	pair<string, string> p("sort", "排序");
	mp.insert(p);

	mp.insert(make_pair("hello", "你好"));

	mp.insert({ "size","大小" });

	for (auto e : mp)
	{
		cout << e.first << ":" << e.second << endl;
	}*/
	vector<string> vs({"apple","banana","apple" ,"apple" ,"apple" ,"apple","banana","banana","banana" });
	map<string, int> mp;
	for (auto e : vs)
	{
		mp[e]++;
	}
	for (auto e : mp)
	{
		cout << e.first << " : " << e.second << " ";
	}
	cout << endl;

}

int main()
{
	TestMap();
	return 0;
}